Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Output string after sring.split("").map breaks into pieces on small screens

With great help from @pratik-wadekar I have the following working text animation. Now my problem is that when I test it on different screen sizes/mobile the animated word plants breaks into pieces. For example PLA and in the next line NTS. How can I avoid this? So it always keeps as one full word.

First I tried to add \xC2\xA0 – non-breaking space or   before and after the word but this doesnt help. The CSS word-wrap property allows long words to be able to break but unfortunately for the reverse case to make a word unbreakable there is no option.

It seems that the CSS word-break: "keep-all property is what I need but when I apply it, it still breaks into pieces on smaller screens.

The Codepen

And App.tsx:

import React from "react";
import { styled } from "@mui/material/styles";
import { Typography } from "@mui/material";

const AnimatedTypography = styled(Typography)`
 & {
   position: relative;
   -webkit-box-reflect: below -20px linear-gradient(transparent, rgba(0, 0, 0, 0.2));
   font-size: 60px;
 }

 & span {
   color: #fbbf2c;
   font-family: "Alfa Slab One", sans-serif;
   position: relative;
   display: inline-block;
   text-transform: uppercase;
   animation: waviy 1s infinite;
   animation-delay: calc(0.1s * var(--i));
 }

 @keyframes waviy {
   0%,
   40%,
   100% {
     transform: translateY(0);
   }
   20% {
     transform: translateY(-20px);
   }
 }
`;

interface Styles extends React.CSSProperties {
 "--i": number;
}

function App() {
 const string = "plants";
 return (
   <Typography variant={"h3"} fontWeight={"bold"}>
     All Your
     <AnimatedTypography>
       {string.split("").map((char, idx) => {
         const styles: Styles = {
           "--i": idx + 1
         };
         return (
           <span key={`${char}-${idx}`} style={styles}>
             {char}
           </span>
         );
       })}
     </AnimatedTypography>
     in One Place
   </Typography>
 );
}

export default App;



about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

Ok I got it. I had to make the animation as own component and add the <AnimatedTypography> the component={"span"} type and white-space: nowrap. Additionally to my const AnimatedTypography = styled(Typography) I had to cast the resulting component with as typeof Typography so Typescript does not throws errors. See here: Complications with the component prop

Then importing the component and addind into the Typography component between my text. Now the layout of my text is preserved and the animation does not split into single characters.

about 4 years ago · Santiago Gelvez Report

0

What you need is white-space: nowrap.

Please check

https://codesandbox.io/s/infallible-matan-rcnclw

about 4 years ago · Santiago Gelvez Report

0

Every single character is a separate <span>, so it's not parsed as a single word. One solution would be to simply make the parent a flex container:

<AnimatedTypography style={{display:"flex"}}>

https://codesandbox.io/s/blissful-sea-4o7498

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!